package com.fivetalks.service;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fivetalks.dao.PostDAO;
import com.fivetalks.dao.ReplyDAO;
import com.fivetalks.domain.Post;
import com.fivetalks.domain.Reply;

@Service(value="postService")
@Transactional
public class PostService {
	@Autowired
	PostDAO postDAO;
	
	@Autowired
	ReplyDAO replyDAO;
	
	@Transactional(readOnly = true)
	public List<Post> getPostList(){
		List<Post> list = postDAO.getAll();
		return list;
	}
	
	@Transactional
	public Post savePost(Post post){
		postDAO.save(post); //영속적,post에 id가 할당.
		return post;
	}
	
	@Transactional
	public void saveReply(long postId,Reply reply){
		Post post=postDAO.select(postId);
		post.addReply(reply);
	}
	
}
